<template>
	<BaseContainer class="report-table-wrapper">
		<div class="r-header">
			<p>南京市养老机构新增床位补贴申请表</p>
			<!-- <p class="text-sm">
				（所属时间： <span class="text-underline">{{ model.year }}</span
				>年第<span class="text-underline">{{getCurrentQuarter(model.month) }}</span
				>季度）
			</p> -->
		</div>
		<ReportTable
			:column="dataListBase"
			:isDetail="isDetail"
			:baseModel="baseModel.organizationInfoPO"
			:model="modelData.organizationInfoPO"
			@change="handleSave"
		></ReportTable>
		<ReportTable
			:column="dataListStaff"
			:isDetail="isDetail"
			:baseModel="baseModel.staffPO"
			:model="modelData.staffPO"
			@change="handleSave"
		></ReportTable>
		<ReportTable
			:column="dataListApply"
			:isDetail="isDetail"
			:baseModel="baseModel.applicationContentPO"
			:model="modelData.applicationContentPO"
			@change="handleSave"
		>
			
		</ReportTable>

		<aplid-dialog @close="onClose" width="85%" v-model="visibleForm" append-to-body whickComm="Archives" :customeHeader="customeHeader" :model="nowOrgInfo">
			<transition name="fade" mode="out-in">
				<div class="dialog-content w-100" v-show="!Loading">
					<ServiceOrgArchives :showBtn="false" :nowRowData="nowOrgInfo"></ServiceOrgArchives>
				</div>
			</transition>
			<PageLoading v-if="Loading" />
		</aplid-dialog>

		<el-drawer size="65%" append-to-body v-model="drawer" :with-header="false"  @close="onClose">
			<practitioner :needPigeonhole="false" v-if="drawer" :isComprehensiveQueries="false" :actionBtn="false"/>
		</el-drawer>
	</BaseContainer>
</template>

<script setup lang="ts">
import { onUnmounted,onMounted,ref,shallowRef,watch } from 'vue'
import ReportTable from '@/views/instOperate/components/ApplyReport/components/ReportTable/index.vue'
import apiMod from '@/apiMod'
import ServiceOrgArchives from '@/views/datacenter/basicData/serviceOrg/components/Archives/index.vue'
import practitioner from '@/views/datacenter/basicData/practitioner/index.vue'
import { useCommonStore } from '@/stores/common'
import {dealBigMoney,filterEmptyObj} from '@/utils/util'
const visibleForm = ref(false)
const {setTempParams,setGloablParams,setMoreSearch} = useCommonStore()
const { Loading } = storeToRefs(useCommonStore())

const props = defineProps<{
  creditCode?:string|number
	params?: any
	editData?: any
	isDetail?: boolean
  caseId?:string|number
  custome?: boolean
  approvalStatus?:string|number
}>()

const emit = defineEmits(['save'])

const model = ref({
	year: '',
	month: '',
})
const baseModel: any = shallowRef({})

const modelData:any = ref({
	organizationInfoPO: {},
	staffPO: {},
	applicationContentPO: {},
})

const drawer = ref(false)
const nowOrgInfo = ref({})

const customeHeader = {
	type: 'CardOne',
	title: 'organizationName',
	avatar: 'organizationLogo',
	tipList: [{ prop: 'operateStatusLabel', type: 'tip-success', label: '运营状态' }],
	tagList: [{ prop: 'organizationTypeLabel', custome: 'tag', type: 'success', label: '机构类型' }],
	menuBtn: [],
}
// 处理数据
let tableData = ref({})




const onClose = ()=> {
  setTempParams({})
  setGloablParams({})
  setMoreSearch({})
}


const  getCurrentQuarter =(nowMonth?:number|string)=> {
  const month:any =nowMonth|| new Date().getMonth() + 1;
  if (month >= 1 && month <= 3) {
    return 1;
  } else if (month >= 4 && month <= 6) {
    return 2;
  } else if (month >= 7 && month <= 9) {
    return 3;
  } else {
    return 4;
  }
}

const getServiceOrgInfo = (creditCode) => {
	if (!creditCode) return
	apiMod.view_dpServiceOrgBase_creditCode(creditCode).then((res) => {
		nowOrgInfo.value = res.data
		visibleForm.value = true
	})
}
const dataListBase = [
	[
		{
			m: '养老机构基本情况',
			bl: 1,
			fs: 16,
			mc: {
				rs: 1,
				cs: 8,
			},
		},
	],
	[
		{ m: '机构名称', style: { width: '200px' } },
		{
			m: '',
			mc:{cs:3},
			prop: 'ORG_NAME',
			link: true,
			showLink: (col, model) => {
				console.log(model)
				getServiceOrgInfo(model.CREDIT_CODE)
			},
		},
		{ m: '法定代表人', style: { width: '200px' } },
		{ m: '', prop: 'LEGAL_NAME' },
	],
	[{ m: '机构地址' }, { m: '',mc:{cs:3}, prop: 'ORG_ADDRESS' }, { m: '邮政编码' }, { m: '', prop: 'POSTAL_CODE' },],
	[{ m: '联系电话' }, { m: '', prop: 'LEGAL_PHONE' }, { m: '身份证号' }, { m: '',mc:{cs:3}, prop: 'ID_CARD' }],
	[{ m: '占地面积' }, { m: '', prop: 'LAND_AREA' }, { m: '使用面积' }, { m: '', prop: 'USABLE_AREA' },{ m: '投资总额' }, { m: '', prop: 'INVESTMENT_AMOUNT' }],
	[{ m: '机构负责人' }, { m: '', prop: 'DUTY_USER' }, { m: '联系电话' }, { m: '', prop: 'DUTY_USER_PHONE' },{ m: '区核定床位数' }, { m: '', prop: 'ORG_ROOM' }],
	[{ m: '资金来源' }, { m: '', prop: 'FUNDING_SOURCE' }, { m: '电子邮件' }, { m: '',mc:{cs:3}, prop: 'EMAIL' }],
	[{ m: '营业执照（民非）证号' }, { m: '',mc:{cs:2}, prop: 'CREDIT_CODE' }, { m: '机构设置证号（备案）',mc:{cs:2} }, { m: '', prop: 'FILING_CODE' }],
	[{ m: '注册资金' }, { m: '',mc:{cs:2}, prop: 'REGISTERED_CAPITAL' }, { m: '入住率',mc:{cs:2} }, { m: '', prop: 'OCCUPANCY_RATE' }],
	[{ m: '开户银行' }, { m: '',mc:{cs:2}, prop: 'BANK_NAME' }, { m: '银行账号',mc:{cs:2} }, { m: '', prop: 'BANK_ACCOUNT' }]
]
const dataListStaff = [
	[
		{
			m: '员 工 概 况',
			bl: 1,
			fs: 16,
			link: true,
			linkType: 'list',
			style: { borderTop: '0px solid #fff' },
			mc: {
				rs: 1,
				cs: 8,
			},
			showLink: (col, model) => {
        const creditCode = modelData.value.organizationInfoPO.creditCode
        setGloablParams({creditCode:creditCode})
				drawer.value = true
			},
		},
	],
	[
		{ m: '管理人员' },
		{ m: '', prop: 'MANAGER_NUM' },
		{ m: '持证人数' },
		{ m: '', prop: 'SATFF_CERT_NUM' },
		{ m: '医技人数' },
		{ m: '', prop: 'MEDICAL_TECHNICAL_STAFF_TOTAL' },
		{ m: '护士人数' },
		{ m: '', prop: 'NURSE_TOTAL' },
	],
	[
		{ m: '护理员数' },
		{ m: '', prop: 'CAREGIVER_TOTAL' },
		{ m: '持证人数' },
		{ m: '', prop: 'CAREGIVER_CERTIFIED_TOTAL' },
		{ m: '工勤人数' },
		{ m: '', prop: 'UTILITY_STAFF_TOTAL' },
		{ m: '员工总数' },
		{ m: '', prop: 'SATFF_NUM' },
	],
]

const applyConfigBase = [
	[
		{
			m: '申 请 内 容(床位核算）',
			bl: 1,
			fs: 16,
			style: { borderTop: '0px solid #fff' },
			mc: {
				rs: 1,
				cs: 8,
			},
		},
	],
	[{ m: '单人间数' },{ m: '', prop: 'SINGLE_ROOM_TOTAL' },{ m: '双人间数' },{ m: '', prop: 'DOUBLE_ROOM_TOTAL' },{ m: '三人间数' },{ m: '', prop: 'TRIPLE_ROOM_TOTAL' },{ m: '多人间数' },{ m: '', prop: 'MULTI_PERSON_ROOM_TOTAL' },
	],
	[{ m: '房间总数' },{ m: '', prop: 'ROOM_TOTAL' },{ m: '床位总数' },{ m: '', prop: 'BED_TOTAL' },{ m: '平均床位建筑面积',mc:{cs:2} },{ m: '', prop: 'AVERAGE_BED_BUILDING_AREA',mc:{cs:2} }
	],
	[{ m: '产权性质(新建/租赁)',mc:{rs:2} },{ m: '',mc:{rs:2}, prop: 'PROPERTY_TYPE' },{ m: '申报普通型床位数' },{ m: '', prop: 'GENERAL_BED_TOTAL' },{ m: '补贴标准（元/  张）',mc:{cs:2} },{ m: '',mc:{cs:2}, prop: 'GENERAL_BED_SUBSIDY' }
	],
	[{ m: '申报护理型床位数' },{ m: '', prop: 'NURSING_BED_TOTAL' },{ m: '补贴标准（元/  张）',mc:{cs:2} },{ m: '',mc:{cs:2}, prop: 'NURSING_BED_SUBSIDY' }
	],
	
	
]
const dataListApply:any= ref([
	
])

const dataListFooter = [
	[
		{
			m: '审核意见',
			bl: 1,
			fs: 16,
			style: { borderTop: '0px solid #fff' },
			mc: {
				rs: 1,
				cs: 8,
			},
		},
	],
	[
		{
			m: '区民政部门意见',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
		{
			m: '',
			prop: 'opinion',
			mc: {
				rs: 1,
				cs: 6,
			},
		},
	],
]
watch(()=>props.editData,(newVal)=>{
	if(newVal&&newVal.applyDetails){
		let data = JSON.parse(props.editData.applyDetails)
		tableData.value = data
		console.log('suoyou',data)
		modelData.value.organizationInfoPO = data
		modelData.value.staffPO = data
		modelData.value.applicationContentPO = data
		// 
		dataListApply.value = [
			...applyConfigBase,
			[{ m: '补贴金额',mc:{rs:2} },{ m: '普通型：',align: 'left',propName:tableData.value['APPLY_SUBSIDY_AMOUNT']},{ m: '大写:',align: 'left',mc:{cs:2},propName:tableData.value['ORDINARY_AMOUNT_CN']},{m: '总金额:',align: 'left',mc:{rs:2,cs:2},propName:tableData.value['APPLY_AMOUNT']},{m: '大写:',align: 'left',mc:{rs:2,cs:2},propName:tableData.value['APPLY_AMOUNT_CN']}
			],
			[{ m: '护理型：',align: 'left',propName:tableData.value['APPLY_NURSE_SUBSIDY_AMOUNT']},{ m: '大写:',align: 'left',mc:{cs:2},propName:tableData.value['NURSE_AMOUNT_CN']}],
			
		]
	}
},{
	immediate:true,
	deep:true
})
onMounted(() => {
	
})
const handleSave = () => {
	emit('save', modelData.value, 'report_1001', props.editData)
}
onUnmounted(() => {
	// emit('save', modelData.value, 'report_1001',props.editData)
})
</script>

<style scoped lang="scss">
.text-underline {
    text-decoration: underline;
    padding: 0 6px;
}
.report-table-wrapper {
	width: 85%;
	margin: 0 auto;
	padding: 10px 30px;
	top: 0;

	.r-header {
		text-align: center;
		font-size: 18px;
		font-weight: bold;
		padding: 15px 0;

		.text-sm {
			font-weight: 400;
			font-size: 16px;
		}
	}
}
</style>
